home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / comm / ums / tools / sumstl / source / sumswrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  6.3 KB  |  262 lines

  1. #define UmsBase UMSBase
  2.  
  3. #include <exec/types.h>
  4.  
  5. #include <clib/exec_protos.h>
  6. #ifdef _DCC
  7. #include <proto/exec.h>
  8. #else
  9. #include <pragmas/exec_pragmas.h>
  10. #include <dos.h>
  11. #endif
  12.  
  13. #include <libraries/ums.h>
  14. #include <clib/ums_protos.h>
  15. #ifdef _DCC
  16. #include <proto/ums.h>
  17. #else
  18. #include <pragmas/ums_pragmas.h>
  19. #endif
  20.  
  21. #include <clib/locale_protos.h>
  22. #ifdef _DCC
  23. #include <proto/locale.h>
  24. #else
  25. #include <pragmas/locale_pragmas.h>
  26. #endif
  27.  
  28.  
  29. #include <dos/dos.h>
  30. #include <dos/datetime.h>
  31. /*#include <dos.h>     woher stammt das eigentlich? es gibt doch nur libraries/dos.h und dos/dos.h?!? [to be deleted] */
  32.  
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <stdlib.h>
  36. #include <ctype.h>
  37.  
  38. #include "date.h"
  39.  
  40.  
  41. // Version String
  42. // --------------
  43.  
  44. static char VersionString[] = "$VER: sumswrite 2.3 (03.11.93)";
  45.  
  46. static char UsageString[] = "\
  47.  Usage: sumswrite <user> <password>\n\
  48.   <user>    : user name.\n\
  49.   <password>: user's password.\n\
  50.   Message will be read from standard input. See docs for file format.\n\
  51. ";
  52.  
  53.  
  54. // Globals
  55. // -------
  56.  
  57. struct Library *UMSBase = NULL;
  58. UMSUserAccount acc = NULL;
  59.  
  60. #define KW_STRING  0
  61. #define KW_NUMBER  1
  62. #define KW_BOOLEAN 2
  63. #define KW_DATE    3
  64.  
  65. struct Keyword
  66. {
  67.     char *name;
  68.     LONG type;
  69.     LONG tag;
  70.     APTR data;
  71. } Keywords[]=
  72. {
  73.     { "MsgNum"      , KW_NUMBER , UMSTAG_WMsgNum      , NULL },
  74.     { "MsgDate"     , KW_DATE   , UMSTAG_WMsgDate     , NULL },
  75.     { "ChainUp"     , KW_NUMBER , UMSTAG_WChainUp     , NULL },
  76.     { "HardLink"    , KW_NUMBER , UMSTAG_WHardLink    , NULL },
  77.     { "SoftLink"    , KW_NUMBER , UMSTAG_WSoftLink    , NULL },
  78.     { "AutoBounce"  , KW_BOOLEAN, UMSTAG_WAutoBounce  , NULL },
  79.     { "HdrFill"     , KW_NUMBER , UMSTAG_WHdrFill     , NULL },
  80.     { "TxtFill"     , KW_NUMBER , UMSTAG_WTxtFill     , NULL },
  81.     { "NoUpdate"    , KW_BOOLEAN, UMSTAG_WNoUpdate    , NULL },
  82.     { "FromName"    , KW_STRING , UMSTAG_WFromName    , NULL },
  83.     { "FromAddr"    , KW_STRING , UMSTAG_WFromAddr    , NULL },
  84.     { "ToName"      , KW_STRING , UMSTAG_WToName      , NULL },
  85.     { "ToAddr"      , KW_STRING , UMSTAG_WToAddr      , NULL },
  86.     { "MsgID"       , KW_STRING , UMSTAG_WMsgID       , NULL },
  87.     { "CreationDate", KW_STRING , UMSTAG_WCreationDate, NULL },
  88.     { "ReceiveDate" , KW_STRING , UMSTAG_WReceiveDate , NULL },
  89.     { "ReferID"     , KW_STRING , UMSTAG_WReferID     , NULL },
  90.     { "Group"       , KW_STRING , UMSTAG_WGroup       , NULL },
  91.     { "Subject"     , KW_STRING , UMSTAG_WSubject     , NULL },
  92.     { "Attributes"  , KW_STRING , UMSTAG_WAttributes  , NULL },
  93.     { "Comments"    , KW_STRING , UMSTAG_WComments    , NULL },
  94.     { "Organization", KW_STRING , UMSTAG_WOrganization, NULL },
  95.     { "Distribution", KW_STRING , UMSTAG_WDistribution, NULL },
  96.     { "Folder"      , KW_STRING , UMSTAG_WFolder      , NULL },
  97.     { "FidoID"      , KW_STRING , UMSTAG_WFidoID      , NULL },
  98.     { "MausID"      , KW_STRING , UMSTAG_WMausID      , NULL },
  99.     { "ReplyGroup"  , KW_STRING , UMSTAG_WReplyGroup  , NULL },
  100.     { "ReplyName"   , KW_STRING , UMSTAG_WReplyName   , NULL },
  101.     { "ReplyAddr"   , KW_STRING , UMSTAG_WReplyAddr   , NULL },
  102.     { "FidoText"    , KW_STRING , UMSTAG_WFidoText    , NULL },
  103.     { "ErrorText"   , KW_STRING , UMSTAG_WErrorText   , NULL },
  104.     { "Newsreader"  , KW_STRING , UMSTAG_WNewsreader  , NULL },
  105.     { NULL,0,0,0 }
  106. };
  107.  
  108.  
  109. // CTRL-C Stuff
  110. // ------------
  111.  
  112. VOID chkabort(VOID) {}
  113. #define ABORTED (SetSignal(0,0) & SIGBREAKF_CTRL_C)
  114.  
  115.  
  116. struct Keyword *FindKeyword(UBYTE *name)
  117. {
  118.     struct Keyword *k;
  119.     for (k=Keywords;k->name;k++)
  120.         if (!strnicmp(name,k->name,strlen(k->name))) return(k);
  121.     return(NULL);
  122. }
  123.  
  124.  
  125. BOOL GetTrueFalse(char *str)
  126. {
  127.     if (!stricmp(str,"true") || !stricmp(str,"on") || !stricmp(str,"yes") || !stricmp(str,"ein") || !stricmp(str,"an") || !stricmp(str,"ja"))
  128.         return(TRUE);
  129.     else
  130.         return(FALSE);
  131. }
  132.  
  133.  
  134. BOOL HandleLine(char *line)
  135. {
  136.     struct Keyword *k;
  137.     int len=strlen(line);
  138.     if (!len) return(TRUE);
  139.     if (line[len-1]=='\n') line[len-1]=0;
  140.     if (!(k=FindKeyword(line))) return(FALSE);
  141.     line+=strlen(k->name);
  142.     while (isspace(*line)) line++;
  143.     if (*line=='=') line++;
  144.     while (isspace(*line)) line++;
  145.     if (!*line && k->type==KW_BOOLEAN) line="true";
  146.     if (!*line) return(TRUE);
  147.     switch (k->type)
  148.     {
  149.         case KW_STRING:    k->data = strdup(line);
  150.                                 break;
  151.         case KW_NUMBER:    k->data = (APTR)atol(line);
  152.                                 break;
  153.         case KW_BOOLEAN:    k->data = (APTR)(*line ? GetTrueFalse(line) : TRUE);
  154.                                 break;
  155.         case KW_DATE:        k->data = (APTR)DateToSeconds(line);
  156.                                 break;
  157.     }
  158.     return(TRUE);
  159. }
  160.  
  161.  
  162. // Main Function
  163. // -------------
  164.  
  165. int main(int argc,char *argv[])
  166. {
  167.     static char buffer[256];
  168.     static struct TagItem Tags[30];
  169.     int erg = RETURN_FAIL;
  170.     BOOL text=FALSE;
  171.     char *textbuf=NULL,*newbuf,*tptr;
  172.     int textbufsize=0,textlen=0,c;
  173.  
  174.     if (argc<3 || argv[1][0]=='?')
  175.     {
  176.         fprintf(stderr,"\33[1m%s\33[0m, written by Stefan Stuntz, Public Domain\n%s",&VersionString[6],UsageString);
  177.         return(RETURN_WARN);
  178.     }
  179.  
  180.     if (UMSBase = OpenLibrary("ums.library",10))
  181.     {
  182.         if (acc = UMSLogin(argv[1],argv[2]))
  183.         {
  184.             while (!feof(stdin))
  185.             {
  186.                 if (text)
  187.                 {
  188.                     if ((c=fgetc(stdin))==EOF) break;
  189.                     if (textlen==textbufsize)
  190.                     {
  191.                         if (!(newbuf=malloc(textbufsize+10001))) { text=FALSE; break; }
  192.                         if (textbuf)
  193.                         {
  194.                             CopyMem(textbuf,newbuf,textbufsize);
  195.                             free(textbuf);
  196.                         }
  197.                         textbuf=newbuf;
  198.                         textbufsize+=10000;
  199.                         tptr=textbuf+textlen;
  200.                     }
  201.                     *tptr++=c;
  202.                     textlen++;
  203.                 }
  204.                 else
  205.                 {
  206.                     if (fgets(buffer,255,stdin))
  207.                     {
  208.                         if (buffer[0]=='-')
  209.                         {
  210.                             text=TRUE;
  211.                         }
  212.                         else if (!HandleLine(buffer))
  213.                         {
  214.                             fprintf(stderr,"\7Invalid line: \"%s\"\n",buffer);
  215.                         }
  216.                     }
  217.                 }
  218.             }
  219.  
  220.             if (text)
  221.             {
  222.                 struct Keyword *k;
  223.                 struct TagItem *t=Tags;
  224.                 for (k=Keywords;k->name;k++)
  225.                 {
  226.                     if (k->data)
  227.                     {
  228.                         t->ti_Tag  = k->tag;
  229.                         t->ti_Data = (LONG)((k->tag==UMSTAG_WGroup && k->data && !stricmp(k->data,"Netmail") ? NULL : (LONG)k->data));
  230.                         t++;
  231.                     }
  232.                 }
  233.                 t->ti_Tag  = UMSTAG_WMsgText;
  234.                 t->ti_Data = (LONG)textbuf;
  235.                 t++;
  236.                 t->ti_Tag = TAG_DONE;
  237.  
  238.                 *tptr=0;
  239.  
  240.                 if (WriteUMSMsg(acc,Tags))
  241.                 {
  242.                     printf("Message written.\n");
  243.                     erg=0;
  244.                 }
  245.                 else
  246.                     fprintf(stderr,"\7UMS-Error %ld: %s\n",UMSErrNum(acc),UMSErrTxt(acc));
  247.             }
  248.             else
  249.                 fprintf(stderr,"\7Missing message text.\n");
  250.  
  251.             UMSLogout(acc);
  252.         }
  253.         else printf("\7UMS-Login failed.\n");
  254.  
  255.  
  256.         CloseLibrary(UMSBase);
  257.     }
  258.     else printf("\7Could not open ums.library V10.\n");
  259.  
  260.     return(erg);
  261. }
  262.